package com.zeyi.web.controller.common;

import cn.hutool.core.lang.Validator;
import com.zeyi.account.service.UserValidateService;
import com.zeyi.common.annotation.Anonymous;
import com.zeyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import static com.zeyi.common.core.domain.AjaxResult.success;

/**
 * 发送验证码
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/verification/send")
public class VerificationCodeController {

    @Autowired
    UserValidateService userValidateService;

    /**
     * 发送手机验证码
     */
    @Anonymous
    @GetMapping("/phone")
    public AjaxResult sendPhoneCode(@RequestParam String phoneNumber) {
        Validator.validateMobile(phoneNumber, "手机号码不正确");
        userValidateService.sendPhoneCode(phoneNumber);
        return success();
    }

    /**
     * 发送邮箱验证码
     */
    @Anonymous
    @GetMapping("/email")
    public AjaxResult sendEmailCode(@RequestParam String email) {
        Validator.validateEmail(email, "邮箱不正确");
        userValidateService.sendEmailCode(email);
        return success();
    }
}
